#Include g:\AHK\git-ahk-lib\Path.ahk

Meta := {
  name: 'MeowPaste'
}

class Init {

  __New(cfs) {
    this.noBgc := cfs.Get('noBgc', false)
    this.guiBgc := cfs.Get('guiBgc', 'abcabc')
    this.useRandomBgc := cfs.Get('useRandomColor', false)
    this.guiTransparent := cfs.Get('guiTRP', 150)
    this.showMask := cfs.Get('showMask', false)
    this.maskBgc := cfs.Get('maskBgc', '000000')
    this.maskInitTransparent := cfs.Get('maskTRP', 100)
    this.showStaticBg := cfs.Get('staticBG', true)
    this.pasteInstantly := cfs.Get('pasteIST', false)
    this.withTip := cfs.Get('tip', false)
    this.clickCount := cfs.Get('trayClick', 1)
    this.clipHK := cfs.Get('clipHK', '!``')
    this.cancelHK := cfs.Get('cancelHK', 'Esc')
    this.clearAllHK := cfs.Get('clearAllHK', '!Esc')
    this.lastHK := cfs.Get('lastHK', '!1')
    this.autoSave := cfs.Get('autoSave', true)
    this.historyLimit := cfs.Get('historyLimit', 100)
    this.guiOption := '+AlwaysOnTop +ToolWindow -Caption +Border'
    this.groupRoot := cfs.Get('groupRoot', Path.Join(A_ScriptDir, 'group'))
    this.hisPath := cfs.Get('hisPath', Path.Join(this.groupRoot, 'history'))
    this.defaultSavePath := cfs.Get('defaultSave', Path.Join(this.groupRoot, 'group\default'))
    this.groupsList := cfs.Get('group').Get('names')

    this._Fix()
    this._EnsureDirectoryExists()
  }

  _Fix() {
    if !this.pasteInstantly && this.noBgc
      this.showMask := true
    if this.historyLimit < 1
      this.autoSave := false
  }

  _EnsureDirectoryExists() {
    for v in Array(_r := this.groupRoot, this.hisPath, this.defaultSavePath) {
      if !DirExist(v) {
        DirCreate(v)
        logger.Warn('创建文件夹 ' v)
      }
    }
    for v in this.groupsList {
      if !DirExist(_r '\' v) {
        DirCreate(_r '\' v)
        logger.Warn('创建分组文件夹 ' v)
      }
    }
  }
}